package com.supermap.business.common;

import com.alibaba.dubbo.config.annotation.Reference;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.common.AreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author:langhongshuai
 * @Description:区域接口层
 * @Date:18/1/8 上午11:25
 */
@Controller
@RequestMapping("AreaController")
public class AreaController {
    /**
     * 使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(AreaController.class);

    @Reference
    private AreaService areaService;

    /**
     * 区域获取
     */
    @RequestMapping("/getAllAreas")
    @ResponseBody
    public JSONUtil getAllAreas(HttpServletRequest request){
        return areaService.getAllAreas();
    }

    /**
     * 通过区域名获取区域
     */
    @RequestMapping("getAreaByName")
    @ResponseBody
    public JSONUtil getAreaCodeByName(HttpServletRequest request){
        String areaName = request.getParameter("areaName");
        return areaService.getAreaByName(areaName);
    }

    /**
     * 通过区域Code获取区域以及下属区域
     */
    @RequestMapping("/getAreasByCode")
    @ResponseBody
    public JSONUtil getAreasByCode(HttpServletRequest request){
        String areaCode = request.getParameter("areaCode");
        return areaService.getAreasByCode(areaCode);
    }

    /**
     * 通过用户id，查询关注区域
     * @param userId
     * @return
     */
    @RequestMapping("/getFocusAreaByUserId")
    @ResponseBody
    public JSONUtil getFocusAreaByUserId(String userId){
        return areaService.getFocusAreaByUserId(userId);
    }

    /**
     * 删除用户关注的区域
     * @param userid
     * @param areaCode
     */
    @RequestMapping("/delFocusAreaCode")
    @ResponseBody
    public JSONUtil delFocusAreaCode(String userid,String areaCode){
        return areaService.delFocusAreaCode(userid,areaCode);
    }


    /**
     * 增加用户关注的区域
     * @param userid
     * @param areaCode
     */
    @RequestMapping("/addFocusAreaCode")
    @ResponseBody
    public JSONUtil addFocusAreaCode(String userid,String areaCode){
        return areaService.addFocusAreaCode(userid, areaCode);
    }
}
